<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
  <input type="text" placeholder="员工姓名" v-model="e.name">
  <input type="text" placeholder="员工工资" v-model="e.sal">
  <input type="text" placeholder="员工工作" v-model="e.job">
  <input type="button" value="添加员工" @click="add()">
  <table border="1">
    <caption>员工列表</caption>
    <tr>
      <th>序号</th>
      <th>姓名</th>
      <th>工资</th>
      <th>工作</th>
      <th>操作</th>
    </tr>
    <tr v-for="(p,i) in arr">
      <td>{{i+1}}</td>
      <td>{{p.name}}</td>
      <td>{{p.sal}}</td>
      <td>{{p.job}}</td>
      <td><input type="button" value="删除" @click="del(i)"></td>
    </tr>
  </table>
</div>
<!--vue+table键,生成一下模板代码,模板代码:file-settings-editor-live templates-
         点+号-命名,描述,代码-->
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<script>
  let v = new Vue({
    el:"body>div",
    data:{
      e:{name:"",sal:"",job:""},
      arr:[{name:"张三",sal:"3000",job:"销售"},
        {name:"李四",sal:"4000",job:"人事"}]
    },
    methods:{
      add(){
        //创建一个新对象 数据来自于双向绑定的员工对象
        v.arr.push({name:v.e.name,sal:v.e.sal,job:v.e.job})
      },
      del(i){
        //从数组中删除元素splice(位置,数量)
        v.arr.splice(i,1)
      }
    }
  })
</script>
</body>
</html>